package com.mysite.springcloud.demo.web.controller;

import com.mysite.springcloud.demo.api.facade.OrderFacade;
import com.mysite.springcloud.demo.api.vo.OrderVo;
import com.mysite.springcloud.demo.api.vo.UserVo;
import com.mysite.springcloud.demo.web.commons.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderFacade orderFacade;

    @RequestMapping("/list")
    @ResponseBody
    public Map<String, Object> list(HttpSession session) {
        Map<String, Object> resultMap = new HashMap<>();
        UserVo user = (UserVo) session.getAttribute(Constants.LOGIN_USER_KEY);
        List<OrderVo> list = orderFacade.getOrdersByUser(user.getId());
        resultMap.put("data", list);
        return resultMap;
    }
}
